import { createStore, Store } from 'vuex';
import { InjectionKey } from 'vue';

// 定义 store2 的状态类型
interface Store2State {
  message: string;
}

// 定义 store2 的注入键
export const store2Key: InjectionKey<Store<Store2State>> = Symbol();

// 创建 store2 实例
export const store2 = createStore<Store2State>({
  state: {
    message: 'Hello from Store 2'
  },
  mutations: {
    updateMessage(state, newMessage: string) {
      state.message = newMessage;
    }
  },
  actions: {
    updateMessageAsync({ commit }, newMessage: string) {
      setTimeout(() => {
        commit('updateMessage', newMessage);
      }, 1000);
    }
  },
  getters: {
    getMessage(state) {
      return state.message;
    }
  }
});